package com.frame.service;

import com.frame.bean.Img;
import com.frame.bean.ImgExample;
import com.frame.dao.ImgMapper;
import com.frame.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ImgService {

    public void upload(Img img){
        SqlSession sqlSession = MyBatisUtil.openSqlSession();
        ImgMapper imgMapper = sqlSession.getMapper(ImgMapper.class);
        imgMapper.insert(img);
        sqlSession.commit();
        if(sqlSession!=null)
            sqlSession.close();
    }

    public Img findImgById(Integer id){
        SqlSession sqlSession = MyBatisUtil.openSqlSession();
        ImgMapper imgMapper = sqlSession.getMapper(ImgMapper.class);
        Img img = imgMapper.selectByPrimaryKey(id);
        if(sqlSession!=null)
            sqlSession.close();
        return img;
    }

    public List<Img> findAllImg(){
        SqlSession sqlSession = MyBatisUtil.openSqlSession();
        ImgMapper imgMapper = sqlSession.getMapper(ImgMapper.class);
        ImgExample imgExample = new ImgExample();
        List<Img> imgList = imgMapper.selectByExample(imgExample);
        if(sqlSession!=null)
            sqlSession.close();
        return imgList;
    }
}
